<html>
<head>
    <meta charset="utf-8">
    <title>取消流程</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<form class="layui-form" action="" style="padding: 0 10px" id="bpmTaskExeForm">

    <table class="layui-table">
        <tr>
            <td>发送提示消息:</td>
            <td>
                <!--通知方式-->
                <div class="layui-input-inline">
                    <#list handlersMap?keys as key>
                    <input type="checkbox" class="layui-input" lay-filter="informType" name="informType" lay-skin="primary" value="${key}"
                           checked="checked"  />
                    <span style="line-height: 44px;">
                            ${handlersMap[key].title }
                        </span>
                </#list>
                </div>
            </td>
        </tr>
        <tr>
            <td>取消原因:</td>
            <td><textarea  name="opinion" placeholder="请输入取消原因" class="layui-textarea"></textarea></td>
        </tr>
    </table>
</form>

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','element', 'setter','form','layer','common'], function () {
        var element = layui.element;
        var $ = layui.$;
        var setter = layui.setter;
        var layer = layui.layer;
        var form = layui.form;
        var common = layui.common;

        window.save=function(index,callback){
            var opinion = $("textarea[name='opinion']").val();
            if(opinion.length==0 || opinion=='' || opinion==undefined){
                layer.msg("取消原因不得为空",{icon:2,time:2000})
                return ;
            }

            var informType = [];
            $("#bpmTaskExeForm table [name='informType']:checked").each(function (index,element) {
                informType.push($(element).val());
            });
            var formData = {ids :"${ids}","opinion": opinion,"informType": informType.toString()};

            $.ajax({
                url:serverPath.workflowPath + setter.workflowLinkPath + "bpmTaskExe/delBatch",
                type: "DELETE",
                data: formData,
                dataType: 'json',
                success : function (res) {
                    if (common.filterRecord(res)) {
                        if(res.data===undefined || res.data===''){
                            //批量取消全部成功
                            layer.msg(res.msg,{time:2500,icon:5,end:function () {
                                    parent.layer.close(index);
                                }
                            });
                            if(callback){ callback()};
                        }else{
                            //批量取消部分成功,其中res.data=取消失败的转办流程名
                            layer.msg(res.msg,{time:2500,icon:6,end:function () {
                                    parent.layer.close(index);
                                }
                            });
                            if(callback){ callback()};
                        }
                    } else {
                            //批量取消全部失败
                        layer.msg(res.msg,{time:2500,icon:6});
                    }
                    return false;
                },
                error : function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("启动失败！" + XMLHttpRequest.status);
                }
            });
        };

    })
</script>
</body>
</html>